package java6681.hotel;

import java.util.Scanner;

public class Hotel6681 {
    //常量EMPTY，用于标记未入住的状态
    private final static String EMPTY = "空";
    //变量rest，表示剩余房间数
    private static int rest;

    public static void main(String[] args) {
        int n = 16;
        String[] room = new String[n];
        initRooms6681(room);
        menu6681(room);
    }

    //初始化客房资源 为“空”
    public static void initRooms6681(String[] room){
        for(int i = 1;i <room.length;i++){
            room[i] = "空";
        }
    }
    //显示当前入住情况 每行三个客房信息
    public static void showRooms6681(String[] room){
        rest = 0;
        System.out.println("当前入住情况：");
        for (int i = 1;i<room.length;i++){
            System.out.print("#" + i + ":" + room[i] + "   ");
            //每行三个客房信息
            if (i % 3 == 0){
                System.out.println();
            }
            //统计剩余客房数
            if (room[i].equals("空")){
                rest++;
            }
            //如果客满，显示今日客满
            if (rest == 0){
                System.out.println("今日客满");
            }
        }
        //显示剩余客房数
        System.out.println();
        System.out.println("****余房：" + rest + "****");
    }
    //显示菜单 选项
    public static void showMenu6681(String[] room){
        System.out.println("=======212006681:张舒婷,绿山家庭旅馆1.0======");
        showRooms6681(room);
        System.out.println();
        System.out.println("       1.-----------入住登记");
        System.out.println("       2.----------- 退房");
        System.out.println("       0.------------结束");
        System.out.println("===========================================");
        System.out.print("请输入您的选择：");
    }
    //显示菜单 使用while循环菜单+switch 设置1.2.0
    public static void  menu6681(String[] room){
        Scanner sc = new Scanner(System.in);
        while(true){
            showMenu6681(room);
            boolean isFlag = true;
            while(isFlag){
                String num = sc.nextLine();
                switch (num){
                    case "1" :
                        in6681(room);
                        isFlag = false;
                        continue;
                    case "2":
                        out6681(room);
                        isFlag = false;
                        continue;
                    case "0":
                        isFlag = false;
                        System.out.println("回车确定");
                        return;
                    default:
                        System.out.println("erro");
                }
            }
            sc.nextLine(); }
    }
    //退房
    public static void out6681(String[] room){
        Scanner scan = new Scanner(System.in);
        System.out.println("输入房间号:");
        int n = scan.nextInt();
        //如果房号正确，设置数组“空”，否则转 重新登记
        if (n > 0 && n <room.length){
            System.out.println("已办理退房");
            System.out.println("按0退出");
            room[n] = "空";
        }else{
            System.out.println("输入错误，重新登记");
            n = scan.nextInt();
        }
    }
    //入住登记
    public static void in6681(String[] room){
        Scanner scan = new Scanner(System.in);
        System.out.println("登记姓名：");
        String n1 = scan.nextLine();
        for (int i = 1;i < room.length;i++){
            if (room[i].equals("空")){
                room[i] = n1;
                System.out.println("入住#" + i );
                System.out.println("按回车确定入住");
                return;
            }
            /*else{
                System.out.println("客满,结束");}
       */
        }
    }
}
